package com.fudan.backend.dao;

import com.fudan.backend.handler.IdTypeHandler;
import com.fudan.backend.handler.ListTypeHandler;
import com.fudan.backend.pojo.CommodityLaunchRequest;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface CommodityLaunchRequestDao {
    @Results(id="commodityLaunchRequestResultMap", value={
            @Result(column = "commodity_launch_request_id", property = "commodityLaunchRequestId", typeHandler = IdTypeHandler.class),
            @Result(column = "store_id", property = "storeId", typeHandler = IdTypeHandler.class),
            @Result(column = "category_id", property = "categoryId", typeHandler = IdTypeHandler.class),
            @Result(column = "pictures", property = "pictures", typeHandler = ListTypeHandler.class)
    })
    @Select("select * from t_commodity_launch_request where commodity_launch_request_id = #{id}")
    CommodityLaunchRequest getCommodityLaunchRequestByCommodityLaunchRequestId(String id);
    @ResultMap("commodityLaunchRequestResultMap")
    @Select("select * from t_commodity_launch_request")
    List<CommodityLaunchRequest> getAllCommodityLaunchRequest();

    @ResultMap("commodityLaunchRequestResultMap")
    @Select("select * from t_commodity_launch_request where store_id = #{id}")
    List<CommodityLaunchRequest> getCommodityLaunchRequestByStoreId(String id);

    @Insert("insert into t_commodity_launch_request values " +
            "(#{commodityLaunchRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{initiateTime}, " +
            "#{processTime}, " +
            "#{storeId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{commodityName}, " +
            "#{categoryId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{price}, " +
            "#{stocks}, " +
            "#{pictures, typeHandler=com.fudan.backend.handler.ListTypeHandler}, " +
            "#{description}, " +
            "#{status}, " +
            "#{info})")
    Integer insertCommodityLaunchRequest(CommodityLaunchRequest commodityLaunchRequest);

    @Update("update t_commodity_launch_request set " +
            "status = #{status} " +
            "where commodity_launch_request_id = #{commodityLaunchRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}")
    Integer setCommodityLaunchRequestStatus(String commodityLaunchRequestId, Integer status);
    @Update("update t_commodity_launch_request set " +
            "info = #{info} " +
            "where commodity_launch_request_id = #{commodityLaunchRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}")
    Integer setCommodityLaunchRequestInfo(String commodityLaunchRequestId, String info);

    @Update("update t_commodity_launch_request set " +
            "info = #{info}, " +
            "status = #{status}," +
            "process_time = #{processTime} " +
            "where commodity_launch_request_id = #{commodityLaunchRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}")
    Integer setStatusInfoProcessTime(String commodityLaunchRequestId, Integer status, String info, Date processTime);


}
